//
//  TextViewController.swift
//  UI
//
//  Created by admin on 14/9/22.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit

class TextViewController: UIViewController, UITextViewDelegate{
    @IBOutlet weak var textView: UITextView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.textView.delegate = self
        self.textView.textAlignment = NSTextAlignment.Left
        self.title = "反馈"
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - UITextViewDelegate
    func textViewShouldBeginEditing(textView: UITextView!) -> Bool{
        return true
    }
    func textViewShouldEndEditing(textView: UITextView!) -> Bool{
        return true
    }
    
    func textViewDidBeginEditing(textView: UITextView!){
        println("dddddddddddddddddddd")
        var rigthBarButtonItem = UIBarButtonItem(title: "发送", style: UIBarButtonItemStyle.Bordered, target: self, action: "send")
        self.navigationItem.rightBarButtonItem = rigthBarButtonItem
        var leftBarButtonItem = UIBarButtonItem(title: "取消", style: UIBarButtonItemStyle.Bordered, target: self, action: "cancel")
        self.navigationItem.leftBarButtonItem = leftBarButtonItem
        
    }
    
    func send(){
        //self.view.resignFirstResponder()
        self.textView.resignFirstResponder()
        self.navigationItem.rightBarButtonItem = nil
        self.dismissViewControllerAnimated(true , completion: {})
        
        println("send---------------")
    }
    
    func cancel(){
        println("cancel---------------")
    }
    func textViewDidEndEditing(textView: UITextView!){
        
    }
    
    func textView(textView: UITextView!, shouldChangeTextInRange range: NSRange, replacementText text: String!) -> Bool{
        return true
    }
    func textViewDidChange(textView: UITextView!){
        
    }
    
    func textViewDidChangeSelection(textView: UITextView!){
//        var range : NSRange!
//        range.length = 0
//        range.location = 0
//        self.textView.selectedRange = range
    }
    
    @availability(iOS, introduced=7.0)
    func textView(textView: UITextView!, shouldInteractWithURL URL: NSURL!, inRange characterRange: NSRange) -> Bool{
        return true
    }
    @availability(iOS, introduced=7.0)
    func textView(textView: UITextView!, shouldInteractWithTextAttachment textAttachment: NSTextAttachment!, inRange characterRange: NSRange) -> Bool{
        return true
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
